package com.baizhi.lyh.service;

import com.baizhi.lyh.dao.UserMapper;
import com.baizhi.lyh.entity.User;
import com.baizhi.lyh.entity.UserExample;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@Transactional
public class UserServiceImpl implements UserService{
    @Autowired
    private UserMapper userMapper;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    public Map<String, Object> queryPage(int page, int pageSize) {
        Map<String,Object> map = new HashMap<>();
        UserExample userExample = new UserExample();
        RowBounds rowBounds = new RowBounds((page-1)*pageSize,pageSize);
        List<User> list = userMapper.selectByExampleAndRowBounds(userExample, rowBounds);
        map.put("rows",list);
        int total = userMapper.selectCount(new User());
        map.put("total",total);
        map.put("page",page);
        return map;
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    public User queryAny(int id) {
        return null;
    }

    @Override
    public Map<String, Object> update(User user) {
        return null;
    }
}
